package com.airconditioner.sales.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.airconditioner.sales.R;

/**
 * 作者：shuizi_wade on 2017/1/17 17:35
 * 邮箱：674618016@qq.com
 */
public class BrandAdapter extends RecyclerView.Adapter<BrandAdapter.ItemViewHolder> {
    private Context mContext;
    private MyItemClickListener itemClickListener;
    private String[] names = {"格力", "大金", "志高", "三洋", "三菱", "美的", "海尔"};

    public BrandAdapter(Context context) {
        mContext = context;
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.activity_product_category_brand_list_row, null);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClickListener.onItemClick(v, (Integer) v.getTag(), names[(Integer) v.getTag()]);
            }
        });
        ItemViewHolder viewHolder = new ItemViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        ItemViewHolder viewHolder = holder;
        viewHolder.itemView.setTag(position);
        holder.nameView.setText(names[position]);
    }

    @Override
    public int getItemCount() {
        return names.length;
    }

    public static class ItemViewHolder extends RecyclerView.ViewHolder {

        public TextView nameView;

        public ItemViewHolder(View itemView) {
            super(itemView);
            nameView = (TextView) itemView.findViewById(R.id.brand_text);
        }
    }

    public interface MyItemClickListener {
        void onItemClick(View view, int postion, String name);
    }

    public void setOnItemClickListener(MyItemClickListener listener) {
        this.itemClickListener = listener;
    }
}
